/*
 * @Author: 晟松
 * @Date: 2021-12-12 16:01:35
 * @LastEditors: 晟松
 * @LastEditTime: 2022-02-04 22:48:23
 * @FilePath: \mini-vue3d:\Code\node\koa2\volunteer-service\src\main\service\UploadService.js
 * @Description: 上传文件和获取七牛token的操作
 */

import sequelize from "@main/db";
import { isNull, isBlank } from "@main/util/ValidateUtil";
import {
    ParamError,
    LoginError,
    NotFoundError,
} from "@main/common/CommonError";
import config from "@main/config";
import blacklist from "blacklist";
import whiteListed from "whitelisted";
import jwt from "jsonwebtoken";
import enums from "@main/config/enums";
import { toEnumNum, toEnumStr } from "@main/util/EnumsUtil";
import { localSave, uploadFile, upToken } from "@main/util/UploadUtils";

// 获取所有定义的model
const models = sequelize.models;

class UploadService {
    static async file(files, params) {
        return await uploadFile(files);
    }

    static async localFile(files, params) {
        return await localSave(files);
    }

    static async imgToken(params) {
        // 这个key为上传文件要保存的名称
        let { key } = params;
        console.log("params: ", params);
        let token = upToken(key);
        return { token, key };
    }
}

export default UploadService;
